package com.example.zkconnect;

import org.apache.zookeeper.*;

import java.io.IOException;

/**
 * @Description
 * @Author 26233
 * @Create 2021-11-02 11:06:52
 */

public class ZkConnection {

    private ZooKeeper zooKeeper;

    public ZkConnection(){ }
    public ZkConnection(String connectString, int sessionTimeout){
        try {
            zooKeeper = new ZooKeeper(connectString, sessionTimeout, new Watcher() {
                public void process(WatchedEvent watchedEvent) {
                    System.out.println("watchedEvent.getState().toString() = " + watchedEvent.getState().toString());
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public ZooKeeper getConnect(){
        return this.zooKeeper;
    }

}
